/**
 * Created by sxx on 2017/10/11.
 */
import "./index.less";
import { projSts } from "../config.js";
import httpurl from "../../../unit/common/js/httpurl";
import chrmDetailTpl from "./supplierchrm_detail.handlebars";


jQuery(function () {
    App.init();

    var id = httpurl.uri.params.id;
    let token = sessionStorage.getItem('token');

    jQuery.ajax({
        url: HOST_ADDR + '/cpmp/splrChrm/getSplrChrm/' + id,
        type: 'get',
        dataType: 'json',
        contentType:"application/json",
        access_token: token,
        headers: {
            'access_token': token,
            'login_type': 'ums'
        },
        success: function(resp){
            if (!resp.success || resp.msgCod !=='S0002') {
                alert(resp.msgCod+' '+resp.msgInf);
                return;
            }
            console.log(resp);
            var imgIcons = resp.data.iconItems;
            if(imgIcons==null || imgIcons ==''){
                alert("该供应商还没有上传风采信息");
                location.href = '/supplier_mng/supplier_chrm_list.html';
            }
            console.log(imgIcons);
            resp.data.imgFmt = [];
            $.each(imgIcons, function(i) {
            	resp.data.imgFmt.push({
            		"iconTitle": imgIcons[i].iconTitle,
            		"chrmIcon": imgIcons[i].chrmIcon,
            		"imgfmtList": HOST_FILE + imgIcons[i].chrmIcon
            	});
            });
	    	console.log(resp.data.imgFmt);
	    	let detailHtml = chrmDetailTpl(resp.data);
	    	$('.basicInfo').html(detailHtml);
           		$(document).on('click', '.J_cancel', function(){
					location.href = '/supplier_mng/supplier_chrm_list.html';
	            });
	    },
        error:function(err){
            console.log(err);
        }
    });
});
